﻿
using System.Collections.Generic;
using Engine;
using Game;

namespace Mekiasm
{
    public class MachineRotateAbleItem : OreCube
    {
        public int[] textureSlots = new int[6];

        public MachineRotateAbleItem(string n) : base(n) { }

        public override int GetFaceTextureSlot(int face, int value)
        {
            return ILibrary.GetFaceTextureSlot(face, value, textureSlots);
        }
        //根据方向不同设置不同的extraData
        public override bool IsInteractive(SubsystemTerrain subsystemTerrain, int value)
        {
            return true;
        }

        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            return ILibrary.GetPlacementValue(subsystemTerrain, componentMiner, value, raycastResult);
        }
        public override bool OnUse(Ray3 aim, ComponentMiner componentMiner, TerrainRaycastResult? raycast)
        {
            if (raycast.HasValue)
            {
                Block block = BlocksManager.Blocks[Terrain.ExtractContents(raycast.Value.Value)];
                if (block.IsInteractive(null, raycast.Value.Value))
                {
                    return true;
                }
            }
            return false;
        }
        public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List<BlockDropValue> dropValues, out bool showDebris)
        {
            showDebris = true;
            int dd = ILibrary.setDirection(oldValue, 0);
            dd = Terrain.ReplaceLight(dd, 0);
            dropValues.Add(new BlockDropValue() { Value = dd, Count = 1 });

        }
        public override void GenerateTerrainVertices(Block block, BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            //根据不同特殊值旋转
            int data = ILibrary.GetDirection(value);
            int rotaionX = 0, rotaionY = 0, rotaionZ = 0;
            switch (data)
            {
                case 1:
                    rotaionX = 0; rotaionY = 3; rotaionZ = 0;
                    break;
                case 2:
                    rotaionX = 0; rotaionY = 2; rotaionZ = 0;
                    break;
                case 3:
                    rotaionX = 0; rotaionY = 1; rotaionZ = 0;
                    break;
                default:
                    break;
            }
            SubsystemMekBlockBehavior.mekModelGenerator.GenerateCubeVerticesBase(block, value, x, y, z, rotaionX, rotaionY, rotaionZ, Color.White, geometry.GetGeometry(ILibrary.texture).OpaqueSubsetsByFace);
        }
        public override float GetDigResilience(int value)
        {
            return 6;
        }
    }
}
